package net.kornr.abstractcanvassamples.client;

import com.google.gwt.widgetideas.graphics.client.Color;

import net.kornr.abstractcanvas.client.CanvasPainter;
import net.kornr.abstractcanvas.client.ICanvasExt;

public class PathTest implements CanvasPainter
{
	public void drawCanvas(ICanvasExt canvas) 
	{
		double width = canvas.getCoordWidth();
		double height = canvas.getCoordHeight();

		double centerx = width/2;
		double centery = height/2;
		double maxradius = Math.min(width/2, height/2);

		canvas.setFillStyle(Color.RED);
		canvas.setStrokeStyle(Color.BLACK);

		
		double angle1 = (Math.PI*2) / 10;
		canvas.moveTo(centerx, centery);
		for (double a = 0; a < Math.PI*2; a+=angle1)
		{
			double x = centerx + Math.cos(a)*maxradius;
			double y = centery + Math.sin(a)*maxradius;
			double x2 = centerx + Math.cos(a+angle1)*maxradius;
			double y2 = centery + Math.sin(a+angle1)*maxradius;

			canvas.beginPath();
			canvas.arc(x, y, 30, 0, Math.PI*2, true);
			canvas.lineTo(x, y);
			canvas.lineTo(x2, y2);
			canvas.lineTo(centerx, centery);
			canvas.closePath();
			canvas.setGlobalAlpha(0.1);
			canvas.fill();
			canvas.setGlobalAlpha(0.5);
			canvas.stroke();
		}	
	}

}
